package com.yycx.module.bus.provider.handler.invoice;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.interceptor.GetInterceptor;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.admin.client.entity.BaseUser;
import com.yycx.module.bus.client.entity.*;
import com.yycx.module.bus.provider.service.BusSupplierBankService;
import com.yycx.module.system.client.entity.SysBank;
import com.yycx.module.system.client.entity.SysFormula;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 开票税金详情扩展
 *
 * @author zyf
 */
@Component("invoicePaymentGetHandler")
public class InvoicePaymentGetHandler implements GetInterceptor {

    @Autowired
    private BusSupplierBankService supplierBankService;

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {
        cq.select(BusPayment.class, "*");
        cq.addSelect(BusInvoiceunitBank.class, "bankName", "bankNo");
        cq.addSelect(BusInvoiceunit.class, "invoiceunitName");
        cq.createJoin(BusInvoiceunitBank.class);
        cq.createJoin(BusInvoiceunit.class);
    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long supplierId = map.getLong("supplierId");
        ResultBody resultBody = supplierBankService.getBySupplierIdAndBankType(supplierId, 2);
        EntityMap supplierBank = (EntityMap) resultBody.getData();
        map.put("supplierBankName",supplierBank.get("bankName"));
        map.put("supplierBankNo",supplierBank.get("bankNo"));
        map.put("supplierName",supplierBank.get("supplierName"));
        map.put("taxNumber",supplierBank.get("taxNumber"));
        map.put("linkMan",supplierBank.get("linkMan"));
        map.put("linkTel",supplierBank.get("linkTel"));
        map.put("address",supplierBank.get("address"));
    }
}
